/**
 * Created by Administrator on 2016/5/6.
 */
$(function () {
    var url=$('#del-url').val();
    var url1=$('#del-url-1').val();
    var url2=$('#del-url-2').val();
    var url3=$('#del-url-3').val();
    var url4=$('#del-url-4').val();
    var url5=$('#del-url-5').val();
    var url_add=$('#add-url').val();
    var url_del_url=$('#del-user-url').val();
    var url_rec_url=$('#rec-user-url').val();
    var app={
        delete:function(obj){
            var loading = layer.load(1);
            $.post(
                url,
                {book_case_id:obj.attr('data-id-del')},
                function(res){
                    layer.close(loading);
                    if(res.status==1){
                        layer.msg(res.info,{icon:1});
                        window.location.reload();
                    }else{
                        layer.msg(res.info,{icon:2});
                        window.location.reload();
                    }
                });
        },
        recover:function(obj){
            var loading = layer.load(1);
            $.post(
                url1,
                {book_case_id:obj.attr('data-id-rec')},
                function(res){
                    layer.close(loading);
                    if(res.status==1){
                        layer.msg(res.info,{icon:1});
                        window.location.reload();
                    }else{
                        layer.msg(res.info,{icon:2});
                        window.location.reload();
                    }
                });
        },

        delete1:function(obj){
            var loading = layer.load(1);
            $.post(
                url2,
                {book_isbn_id:obj.attr('data-id-del1')},
                function(res){
                    layer.close(loading);
                    if(res.status==1){
                        layer.msg(res.info,{icon:1});
                        window.location.reload();
                    }else{
                        layer.msg(res.info,{icon:2});
                        window.location.reload();
                    }
                });
        },
        recover1:function(obj){
            var loading = layer.load(1);
            $.post(
                url3,
                {book_isbn_id:obj.attr('data-id-rec1')},
                function(res){
                    layer.close(loading);
                    if(res.status==1){
                        layer.msg(res.info,{icon:1});
                        window.location.reload();
                    }else{
                        layer.msg(res.info,{icon:2});
                        window.location.reload();
                    }
                });
        },

        delete2:function(obj){
            var loading = layer.load(1);
            $.post(
                url4,
                {book_type_id:obj.attr('data-id-del2')},
                function(res){
                    layer.close(loading);
                    if(res.status==1){
                        layer.msg(res.info,{icon:1});
                        window.location.reload();
                    }else{
                        layer.msg(res.info,{icon:2});
                        window.location.reload();
                    }
                });
        },
        recover2:function(obj){
            var loading = layer.load(1);
            $.post(
                url5,
                {book_type_id:obj.attr('data-id-rec2')},
                function(res){
                    layer.close(loading);
                    if(res.status==1){
                        layer.msg(res.info,{icon:1});
                        window.location.reload();
                    }else{
                        layer.msg(res.info,{icon:2});
                        window.location.reload();
                    }
                });
        },

        add:function(obj){
            var loading = layer.load(1);
            $.post(
                url_add,
                {a_name:$('#a_name').val(),a_email:$('#a_email').val(),a_pwd:$('#a_pwd').val(),a_repwd:$('#a_repwd').val(),a_tel:$('#a_tel').val(),a_department:$('#a_department').val()},
                function(res){
                    layer.close(loading);
                    if(res.status==1){
                        layer.msg(res.info,{icon:1});
                        window.location.reload();
                    }else{
                        layer.msg(res.info,{icon:2});
                        window.location.reload();
                    }
                });
        },

        del_user:function(obj){
            var loading = layer.load(1);
            $.post(
                url_del_url,
                {a_id:obj.attr('data-del-url')},
                function(res){
                    layer.close(loading);
                    if(res.status==1){
                        layer.msg(res.info,{icon:1});
                        window.location.reload();
                    }else{
                        layer.msg(res.info,{icon:2});
                        window.location.reload();
                    }
                });
        },

        rec_user:function(obj){
            var loading = layer.load(1);
            $.post(
                url_rec_url,
                {a_id:obj.attr('data-rec-url')},
                function(res){
                    layer.close(loading);
                    if(res.status==1){
                        layer.msg(res.info,{icon:1});
                        window.location.reload();
                    }else{
                        layer.msg(res.info,{icon:2});
                        window.location.reload();
                    }
                });
        },


    }
    $('.del').click(function(){
        app.delete($(this));
    });
    $('.rec').click(function(){
        app.recover($(this));
    });
    $('.del1').click(function(){
        app.delete1($(this));
    });
    $('.rec1').click(function(){
        app.recover1($(this));
    });
    $('.del2').click(function(){
        app.delete2($(this));
    });
    $('.rec2').click(function(){
        app.recover2($(this));
    });
    $('.add').click(function(){
        app.add($(this));
    });
    $('.del_user').click(function(){
        app.del_user($(this));
    });
    $('.rec_user').click(function(){
        app.rec_user($(this));
    });
});